<?php
/**
 * @author 天涯 <mail@phpha.com>
 * @copyright http://blog.phpha.com
 * @link http://blog.phpha.com/vncms
 * @version 1.0
 */
defined('APP_PATH') or exit('Access Denied');
require 'check.php';
class spag extends check{
	//单页列表
	public function lis(){
		$page = (int) $this->spArgs('page',1) > 1 ? (int) $this->spArgs('page',1) : 1;
		$this->spag = spClass('m_spag')->spPager($page,15)->findAll();
		$this->pager = spClass('m_spag')->spPager()->getPager();
		$this->display('spag_lis.tpl.php');
	}
	//添加单页
	public function add(){
		$this->display('spag_add.tpl.php');
	}
	//执行添加
	public function doadd(){
		if(false != spClass('m_spag')->spVerifier($this->spArgs()))	$this->error('数据验证错误！',spUrl('spag','add'));
		if(false != spClass('m_spag')->create($this->spArgs())){
			$this->success('添加单页成功！',spUrl('spag','lis'));
		}else{
			$this->error('添加单页失败！',spUrl('spag','add'));
		}
	}
	//更新单页
	public function upd(){
		if(!$id = intval($this->spArgs('id')))	$this->error('缺少必要参数！',spUrl('spag','lis'));
		$this->spag = spClass('m_spag')->find(array('id'=>$id));
		$this->display('spag_upd.tpl.php');
	}
	//执行更新
	public function doupd(){
		if(false != spClass('m_spag')->spVerifier($this->spArgs()))	$this->error('数据验证错误！',spUrl('spag','lis'));
		if(false != spClass('m_spag')->update(array('id'=>$this->spArgs('id')),$this->spArgs())){
			$this->success('更新单页成功！',spUrl('spag','lis'));
		}else{
			$this->error('更新单页失败！',spUrl('spag','lis'));
		}
	}
	//删除单页
	public function del(){
		if(!$id = intval($this->spArgs('id')))	$this->error('缺少必要参数！',spUrl('spag','lis'));
		if(false != spClass('m_spag')->delete(array('id'=>$id))){
			$this->success('删除单页成功！',spUrl('spag','lis'));
		}else{
			$this->error('删除单页失败！',spUrl('spag','lis'));
		}
	}
}
